package cn.yangsen.simplebeanmanager.bean.html;

import lombok.Getter;
import lombok.ToString;
import cn.yangsen.simplebeanmanager.bean.html.itfc.Cleanable;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

@XStreamAlias("input")
@ToString(callSuper = true)
public class Checkbox extends Input implements Cleanable
{
	@Getter
	@XStreamAsAttribute
	private final InputType type = InputType.Checkbox;

	@Getter
	@XStreamAsAttribute
	private Boolean checked;

	public Checkbox()
	{
		setValue("true");
	}

	public Checkbox(String name, boolean checked)
	{
		this();
		setName(name);
		setChecked(checked);
	}

	public void setChecked(boolean checked)
	{
		if (checked)
		{
			this.checked = checked;
		}
		else
		{
			this.checked = null;
		}
	}

	@Override
	public void clean()
	{
		checked = null;
	}
}
